package com.kmxd.ams.core.exception;

import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.common.enums.ParamsValidateType;

import javax.validation.constraints.NotNull;

/**
 * 参数校验失败
 *
 * @author nickbi
 * @date 2021 /12/9 11:06
 */
public class ParamsValidateException extends AbstractException {
  private ParamsValidateType type;
  private String fieldName;
  /**
   * 校验失败
   *
   * @param type 参数校验对应类型
   */
  public ParamsValidateException(
      @NotNull final LogInfo recordInfo,
      @NotNull String fieldName,
      @NotNull ParamsValidateType type) {
    super(recordInfo, ErrorCode.VALIDATE_ERROR, fieldName + type.getName());
    this.type = type;
    this.fieldName = fieldName;
  }

  public ParamsValidateType getType() {
    return type;
  }

  public void setType(ParamsValidateType type) {
    this.type = type;
  }

  public String getFieldName() {
    return fieldName;
  }

  public void setFieldName(String fieldName) {
    this.fieldName = fieldName;
  }

  @Override
  public String toString() {
    return "ParamsValidateException{"
        + "type="
        + type
        + ", fieldName='"
        + fieldName
        + '\''
        + "} "
        + super.toString();
  }

  public static ParamsValidateException instance(
      @NotNull String fieldName, @NotNull ParamsValidateType type) {
    return new ParamsValidateException(LogInfo.newCallerInstance(), fieldName, type);
  }
}
